package com.tueye.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.tueye.base.util.BaseService;
import com.tueye.base.util.Page;
import com.tueye.cache.TuEyeCache;
import com.tueye.dao.ITopicDao;
import com.tueye.entity.Comment;
import com.tueye.entity.Pictures;
import com.tueye.entity.TopicType;
import com.tueye.entity.Topics;
import com.tueye.entity.user.Flowers;
import com.tueye.entity.user.User;
import com.tueye.entity.user.UserCollectionInfo;
import com.tueye.service.ITopicService;
import com.tueye.service.exception.TuEyeServiceException;
import com.tueye.utils.FileHandle;
import com.tueye.utils.TuEyeConstant;
/**
 * 
 * @author yuyue 
 *  Time:2008/12/23
 *  Description: publish topic service 
 */
@Scope("prototype")
@Component("topicService")
public class ITopicServiceImpl extends BaseService implements ITopicService{
	
	@Autowired
	@Qualifier("topicDao")
	private ITopicDao topicDao;
	
	@Autowired
	@Qualifier("tueyecache")
	private TuEyeCache tueyecache;
	
	FileHandle fileHandle = new FileHandle();
	
	/**
	 * check the topictype folds whether create,if don't have,create it.
	 */
	@Override
	public void checkTopicTypeFolds() {
		// TODO Auto-generated method stub
		for(TopicType ttype : tueyecache.allTopicTypes() ){
			fileHandle.cerateDirectory(TuEyeConstant.PROJECTPATH + ttype.getType_enlish_name());
		}
	}

	@Override
	public TopicType getTopicTypeById(String typeid) {
		// TODO Auto-generated method stub
		return topicDao.getTopicTypeById(typeid);
	}

	@Override
	public void saveTopics(Topics topic) {
		// TODO Auto-generated method stub
		topicDao.saveTopics(topic);
		
	}

	@Override
	public Topics getTopicById(String id) {
		// TODO Auto-generated method stub
		return topicDao.getTopicById(id);
	}

	@Override
	public void savePicture(Pictures picture) {
		// TODO Auto-generated method stub
		topicDao.savePicture(picture);
	}

	@Override
	public Page pagedQueryByHQL(String hql, int pageNo, int pageSize,
			Object... values) throws TuEyeServiceException {
		// TODO Auto-generated method stub
		return topicDao.pagedQueryByHQL(hql, pageNo, pageSize, values);
	}

	@Override
	public void addTopicType(TopicType tt) {
		// TODO Auto-generated method stub
		topicDao.addTopicType(tt);
	}

	@Override
	public List<Comment> getAllCommentsByPId(String picid) {
		// TODO Auto-generated method stub
		return topicDao.getAllCommentsByPId(picid);
	}

	@Override
	public Pictures getPictureById(String picid) {
		// TODO Auto-generated method stub
		return topicDao.getPictureById(picid);
	}

	@Override
	public void saveComment(Comment comment) {
		// TODO Auto-generated method stub
		topicDao.saveComment(comment);
	}
	@Override
	public void delTopic(String id) throws TuEyeServiceException {
		topicDao.delTopic(id);
		
	}

	@Override
	public void delePictures(String hql) throws TuEyeServiceException {
		topicDao.delePictures(hql);
		
	}

	@Override
	public void delePic(String id, String picpath) throws TuEyeServiceException {
		topicDao.delePic(id, picpath);
		
	}

	@Override
	public void saveTopicCollect(UserCollectionInfo collectinfo) {
		// TODO Auto-generated method stub
		topicDao.saveTopicCollect(collectinfo);
	}

	@Override
	public void saveFlower(Flowers flower) {
		// TODO Auto-generated method stub
		topicDao.saveFlower(flower);
	}

	@Override
	public void updateTopic(Topics topic) {
		// TODO Auto-generated method stub
		topicDao.updateTopic(topic);
		
	}

	@Override
	public int getCommentsNumByTopicId(String topicid) {
		// TODO Auto-generated method stub
		
		return topicDao.getCommentNumByTopicId(topicid);
	}

	@Override
	public User getUserByTopic(Topics topic) {
		// TODO Auto-generated method stub
		return topicDao.getUserByTopic(topic);
	}

	@Override
	public List queryBysql(String sql) {
		// TODO Auto-generated method stub
		return topicDao.queryBysql(sql);
	}

	@Override
	public List<Topics> getTopicsByHql(String hql) throws TuEyeServiceException {
		// TODO Auto-generated method stub
		return topicDao.getTopicsByHql(hql);
	}

	@Override
	public Map<String, Object> getDingOrCaiNum(String topicid)
			throws TuEyeServiceException {
		// TODO Auto-generated method stub
		return topicDao.getFlowerNum(topicid);
	}

	@Override
	public String getClickNumByTopicId(String topicid)
			throws TuEyeServiceException {
		
		return topicDao.getClickNumByTopicId(topicid);
	}

	@Override
	public List getFlowerByTopicsId(String topicsId) {
		return topicDao.getFlowerByTopicsId(topicsId);
	}
	
 
	

	 
	
	
	
	
	
	

}
